/*
 * @(#)Theme.java        0.1 09/04/29
 * @version 	0.1 29 Apr 2009
 * @author 	Nguyen Thang Huy
 * 
 * Luu tru du lieu cua 1 theme
 */


package Data;

import XML_IO.*;
import org.w3c.dom.*;

public class Theme {
	String name;
	String folder;
	boolean _isCurrent;
	
	public Theme() {
		name = "";
		folder = "";
		_isCurrent = false;
	}
	
	/*
	 * Doc du lieu cua 1 theme tu XML
	 */
	public Theme(Node node) {
		this();
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			setName(XML_IO.getElementValue(node));
			NamedNodeMap attributes = node.getAttributes();
			for (int k=0; k<attributes.getLength(); k++)
	    	{
	    		Node attribute = attributes.item(k);
	    		if (attribute.getNodeName().equals("folder")) {
	    			setFolder(attribute.getNodeValue());
	    		}
	    		if (attribute.getNodeName().equals("isCurrent") && XML_IO.getElementValue(attribute).equals("true")) {
	    			setCurrent(true);
	    		}
	    	}
		}
	}
	
	public String getName() {
		return name;
	}
	public String getFolder() {
		return folder;
	}
	
	public boolean isCurrent() {
		return _isCurrent;
	}
	public void setName(String n) {
		name = n;
	}
	
	public void setFolder(String f) {
		folder = f;
	}
	public void setCurrent(boolean b) {
		_isCurrent = b;
	}
	
	/*
	 * Chuyen du lieu 1 theme thanh XML
	 */
	public Node toXml(Document doc) {
    	Element themeElement = doc.createElement("theme");
    	themeElement.appendChild(doc.createTextNode(name));
    	themeElement.setAttribute("folder", folder);
    	themeElement.setAttribute("isCurrent", _isCurrent + "");
    	return themeElement;
	}
}
